import { setStorage } from '@/utils/utils.js'
// import { setLogin } from '@/service/common.js'
import common from './common.js'
export default {
	namespaced: true,
	state: {
		userToken: null,
		userInfo: null,
		tempAddressInfo: null
	},
	mutations: {
		SET_USERTOKEN(state, value){
			setStorage('token', value)
			state.userToken = value
		},
		SET_USERINFO(state, value){
			setStorage('userInfo', value)
			state.userInfo = value
		},
		SET_ADDRESSINFO(state, value){
			state.tempAddressInfo = value
		},
	},
	actions: {
		// 获取小程序用户信息
		async getUserInfo({
			commit
		}, data) {
			wx.login({
				success: res => {
					// self.$store.dispatch('user/getUserInfo', res)
					setLogin(res).then( res => {
						commit('SET_USERTOKEN', res.data.token)
						commit('SET_USERINFO', res.data)
					})
				}
			})
		},
	}
}
